<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="王佳佳">
    <title></title>
    <style>
        .box
        {
            width: 520px;
            height: 280px;
            margin: auto;
            margin-top: 100px;
            margin-bottom: 5px;
            position: relative;
        }
        ul
        {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        li
        {
            position: absolute;
            display: none;
        }
        li.current
        {
            display: block;
        }
        section
        {
            width: 170px;
            height: 20px;
            /* border: 1px solid; */
            display: flex;
            justify-content: space-around;
            align-items: center;
            margin: auto;
        }
        aside
        {
            width: 10px;
            height: 10px;
            border: 1px solid;
            border-radius: 5px;
            cursor: pointer;
        }


        .lastimg,
        .nextimg {
            position: absolute;
            width: 20px;
            height: 30px;
            line-height: 30px;
            font-weight: bold;
            text-align: center;
            background-color: gray;
            color: white;
            opacity: 0.7;
            top: 120px; 
            cursor: pointer;
            display: none;
        }

        .lastimg {
            left: calc((100% - 520px) / 2);
            border-top-left-radius: 5px;
            border-bottom-left-radius: 5px;
        }

        .nextimg {
            right: calc((100% - 520px) / 2);
            border-top-right-radius: 5px;
            border-bottom-right-radius: 5px;
        }

        

        .black
        {
            background-color: black;
        }
    </style>
</head>
<body>
    <div class="box">
        <ul>
            <!-- (li>a[href=#]>img)*5 -->
            <li class="current"><a href="#"><img src="img/01.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/02.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/03.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/04.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/05.jpg" alt=""></a></li>
        </ul>
        <div class="lastimg">
            &lt;
        </div>
        <div class="nextimg">
            &gt;
        </div>
    </div>
    <section>
        <aside class="black"></aside>
        <aside></aside>
        <aside></aside>
        <aside></aside>
        <aside></aside>
    </section>
</body>
</html>

<script>
    //轮播图
    var lis = document.querySelectorAll('li');
    var asides = document.querySelectorAll('aside');
    var index = 0;
    var changeimg = setInterval(change,1500);
    function change()
    {
        for(var i = 0; i < lis.length; i++)
        {
            lis[i].className = '';
            asides[i].className = '';
        }
        index ++;
        if(index == 5)
        {
            index = 0;
        }
        lis[index].className = 'current';
        asides[index].className = 'black';
    }



    //小黑点
    window.onload = function()
    {
        for(var i = 0; i < asides.length; i++)
        {

            lis[i].index = i;
            asides[i].index = i;                                //不理解  ！！！！！！！！！！！！！！！！！！！！


            asides[i].onmouseenter = function()
            {
                clearInterval(changeimg);

                for(var i = 0; i < asides.length; i++)
                {
                    asides[i].className = '';
                    lis[i].className = '';
                }
                // this.className = 'black';
                asides[this.index].className = 'black';
                lis[this.index].className = 'current';
            }
            asides[i].onmouseout = function()
            {
                this.style.backgroundColor = '';
                changeimg = setInterval(change,1500);
            }
        }
    }




    //点击换图
    var box = document.querySelector('.box');
    var lastimg = document.querySelector('.lastimg');
    var nextimg = document.querySelector('.nextimg');


    box.onmouseenter = function()
    {
        lastimg.style.display = 'block';
        nextimg.style.display = 'block';
    }

        //上一张
    var n = 0;
    lastimg.onclick = function()
    {   
        for(var m =0; m <asides.length; m++)
        {
            asides[m].className = '';
        }
        n ++;
        asides[n - 1].className = 'black';
        lis[n - 1].className = 'current';
    }
</script>